import user.AdminUser;
import user.NormalUser;
import user.ProxyUser;
import user.factory.AdminUserFactory;
import user.factory.NormalUsrFactory;

import java.util.Scanner;

public class LibrarySystem {


    public ProxyUser selectProxyRole(ProxyUser proxyUserAdmin,ProxyUser proxyUserNormalW,ProxyUser proxyUserNormalL) {
        System.out.println("选择角色进行登录");
        System.out.println("1.管理员\n2.普通用户(关羽)\n3.普通用户(张飞)");

        ProxyUser currentUser = null;

        Scanner sc = new Scanner(System.in);

        int choice = sc.nextInt();
        switch(choice) {
            case 1:
                currentUser = proxyUserAdmin;
                break;
            case 2:
                currentUser = proxyUserNormalW;
                break;
            case 3:
                currentUser = proxyUserNormalL;
            case 4:
                System.exit(0);
                System.out.println("系统已经退出");
                break;
            default:
                System.out.println("非法输入");
                break;
        }

        return currentUser;
    }

    public static void main(String[] args) {
        //初始化用户，一个管理员，两个普通用户。
        AdminUserFactory adminUserFactory = new AdminUserFactory();

        NormalUsrFactory normalUsrFactory = new NormalUsrFactory();

        AdminUser adminUser = (AdminUser) adminUserFactory.createUser("刘备",1);

        NormalUser normalUser1 = (NormalUser) normalUsrFactory.createUser("关羽",2);

        NormalUser normalUser2 = (NormalUser) normalUsrFactory.createUser("张飞",3);


        ProxyUser proxyAdminUser = new ProxyUser(adminUser);
        ProxyUser proxyNormalUser1 = new ProxyUser(normalUser1);
        ProxyUser proxyNormalUser2 = new ProxyUser(normalUser2);

        LibrarySystem librarySystem = new LibrarySystem();

        //选择相对应的角色进行登录
        ProxyUser currentUser = librarySystem.selectProxyRole(proxyAdminUser,proxyNormalUser1,proxyNormalUser2);

        while(true) {
            int choice = currentUser.getRealUser().display();
        }
    }

}
